//


#import "NT_AddressTableViewCell.h"

//
@interface NT_AddressTableViewCell ()
/** name*/
@property (nonatomic, strong) UILabel *nameLabel;
/** phone*/
@property (nonatomic, strong) UILabel *phoneLabel;
/** dizhi*/
@property (nonatomic, strong) UILabel *contentLabel;
/** bianji*/
@property (nonatomic, strong) UIButton *editBtn;
/** shenchu*/
@property (nonatomic, strong) UIButton *deleteBtn;
/** xian*/
@property (nonatomic, strong) UIView *lineView;

@end

@implementation NT_AddressTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
      //
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = RGB(30, 30, 30);
        self.nameLabel.font = FontPFMedium(kRelativeWidth(16));
        self.nameLabel.text = @"";
        [self.contentView addSubview:self.nameLabel];
        
        self.phoneLabel = ({
            UILabel *label = [[UILabel alloc]init];
            label.textColor = rgba(60, 60, 60, 1);
            label.font = FontPFRegular(kRelativeWidth(16));
            label.text = @"";
            [self.contentView addSubview:label];
            label;
        });
        
        self.contentLabel = ({
            UILabel *label = [[UILabel alloc]init];
            label.textColor = rgba(90, 90, 90, 1);
            label.font = FontPFRegular(kRelativeWidth(15));
            label.text = @"";
            [self.contentView addSubview:label];
            label;
        });
        
        self.lineView = ({
            UIView *view = [UIView new];
            view.backgroundColor = RGB(239, 239, 239);
            [self.contentView addSubview:view];
            view;
        });
        
        self.editBtn = ({
            UIButton *button = [[UIButton alloc]init];
            [button setImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(EditAction) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:button];
            button;
        });
        
        self.deleteBtn = ({
            UIButton *button = [[UIButton alloc]init];
            [button setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:button];
            button;
        });
        
        
        
    }
    return  self;
}

- (void)setNeedsLayout {
    [super setNeedsLayout];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRelativeHeight(10));
        make.left.mas_offset(kRelativeWidth(15));
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.nameLabel);
        make.left.mas_equalTo(self.nameLabel.mas_right).offset(kRelativeWidth(20));
        make.height.mas_equalTo(self.nameLabel);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(kRelativeHeight(10));
        make.left.mas_offset(kRelativeWidth(15));
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(kRelativeHeight(10));
        make.left.mas_offset(kRelativeWidth(15));
        make.right.mas_offset(0);
        make.height.mas_equalTo(0.6);
    }];
    
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(kRelativeHeight(10));
        make.right.mas_offset(-kRelativeWidth(30));
        make.width.height.mas_equalTo(kRelativeWidth(35));
    }];
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(kRelativeHeight(10));
        make.right.mas_equalTo(self.deleteBtn.mas_left).offset(-kRelativeWidth(20));
        make.width.height.mas_equalTo(kRelativeWidth(35));
    }];
    
}
//SEtmodel
- (void)setModel:(AddressModel *)model {
    _model = model;
    //
    self.nameLabel.text = model.name;
    self.phoneLabel.text = model.phone;
    self.contentLabel.text = [NSString stringWithFormat:@"%@%@",model.area,model.detail];
    
    
}

//
- (void)EditAction {
    if ([self.delegate respondsToSelector:@selector(editActionCell:)]) {
        [self.delegate editActionCell:self];
    }
    
}
//
- (void)deleteAction {
    if ([self.delegate respondsToSelector:@selector(deleteActionCell:)]) {
        [self.delegate deleteActionCell:self];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
